package com.hemaapp.yjnh.view;

import com.hemaapp.yjnh.R;

import android.app.Activity;
import android.graphics.drawable.ColorDrawable;
import android.os.Handler;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.FrameLayout.LayoutParams;
import xtom.frame.XtomObject;

/**弹出：已经关注，取消关注等消息
 * @author GuiyouZhang
 * Date：2016年1月15日 上午9:39:01
 * Email:guiyouzhang@163.com
 */
public class ShowTextPop extends XtomObject {

	private Activity mContext;
	private View father;
	private ViewGroup mViewGroup;

	private PopupWindow mWindow;
	private TextView textV;

	public ShowTextPop(Activity context, View activityRootView) {
		mContext = context;
		father = activityRootView;
		mWindow = new PopupWindow(mContext);
		mWindow.setWidth(LayoutParams.MATCH_PARENT);
		mWindow.setHeight(LayoutParams.MATCH_PARENT);
		mWindow.setBackgroundDrawable(new ColorDrawable(0x55000000));
		mWindow.setFocusable(true);
//		mWindow.setAnimationStyle(R.style.PopupAnimation);
		mViewGroup = (ViewGroup) LayoutInflater.from(mContext).inflate(
				R.layout.pop_cache_success, null);
		textV = (TextView) mViewGroup.findViewById(R.id.tv);
		mWindow.setContentView(mViewGroup);
	}

	public void setText(String content) {
		textV.setText(content);
	}

	public void setDrawable(int left, int top, int right, int bottom) {
		textV.setCompoundDrawablesWithIntrinsicBounds(left == 0 ? null
				: mContext.getResources().getDrawable(left), top == 0 ? null
				: mContext.getResources().getDrawable(top), right == 0 ? null
				: mContext.getResources().getDrawable(right),
				bottom == 0 ? null : mContext.getResources()
						.getDrawable(bottom));
	}

	public void show() {
		log_i("pop show-----------");
		mWindow.showAtLocation(father, Gravity.BOTTOM, 0, 0);
		new Handler().postDelayed(new Runnable() {
			
			@Override
			public void run() {
				// TODO Auto-generated method stub
				dimiss();
			}
		}, 1000);
	}

	public void dimiss() {
		mWindow.dismiss();
	}
}
